package service;

import Util.DaoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import dao.ProductMapper;
import entity.Category;
import entity.Product;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

/**
 * ClassName:TestProduct
 * Package:service
 *
 * @date:2021/10/28 6:54 下午
 * @author: Tiangle
 */
public class TestProduct {
    DaoUtil du = DaoUtil.getDu();
//    1.查询商品及其分类信息
    @Test
    public void select01(){
        SqlSession sqlS = du.getSqlS();
        ProductMapper mapper = sqlS.getMapper(ProductMapper.class);
        Product p = mapper.getP(2);
        System.out.println(p);
        sqlS.close();
//
//        SqlSession sqlS2 = du.getSqlS();
//        ProductMapper mapper2 = sqlS2.getMapper(ProductMapper.class);
//        Product p2 = mapper2.getP(2);
//        System.out.println(p2);
//        sqlS2.close();

    }
//    2.查询所有分类及其商品信息
    @Test
    public void select02(){
        SqlSession sqlS = du.getSqlS();
        ProductMapper mapper = sqlS.getMapper(ProductMapper.class);
        List<Category> cat = mapper.getCat();
        for (Category c :
                cat) {
            System.out.println( c.getCname());
        }
        sqlS.close();
    }
//    3.查询商品及其分类和评论信息
    @Test
    public void select03(){
        SqlSession sqlS = du.getSqlS();
        ProductMapper mapper = sqlS.getMapper(ProductMapper.class);
        Product cat = mapper.getOP(1);
        System.out.println(cat);
        sqlS.close();
    }
    @Test
    public void seltct04(){
        //设置分页信息
        PageHelper.startPage(1,2);
        SqlSession sqlS = du.getSqlS();
        ProductMapper mapper = sqlS.getMapper(ProductMapper.class);
        List<Product> getalls = mapper.getall();
        //商品分页
        PageInfo<Product> productPageInfo = new PageInfo<>(getalls);
        //取出分页的list
        List<Product> list = productPageInfo.getList();
        for (Product product : list) {
            System.out.println(product);
        }
        sqlS.close();
    }

}
